﻿using FluentAssertions;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace Sustainalytics.ScreeningTool.Synchronization.Tests.Extensions.StringExtensionsTests
{
    [Trait("Category", "Unit")]
    public class StripLineBreaks_Should
    {
        private const string LineBreakReplacement = StringExtensions.LineBreakReplacement;

        [Fact]
        public void return_null_for_null_value()
            => ((string)null).StripLineBreaks().Should().Be(null);

        [Fact]
        public void return_empty_string_for_empty_string_value()
            => "".StripLineBreaks().Should().Be("");

        [Fact]
        public void return_value_unchanged_if_value_has_no_line_breaks()
            => "bla".StripLineBreaks().Should().Be("bla");

        [Fact]
        public void replace_carriage_return_from_value()
            => "\r".StripLineBreaks().Should().Be(LineBreakReplacement);

        [Fact]
        public void replace_line_feed_from_value()
            => "\n".StripLineBreaks().Should().Be(LineBreakReplacement);

        [Fact]
        public void replace_carriage_return_and_line_feed_from_value()
            => "\r\n".StripLineBreaks().Should().Be(LineBreakReplacement);

        [Fact]
        public void replace_all_line_breaks_from_value()
            => "bla\rbla\nbla\r\nbla".StripLineBreaks().Should().Be($"bla{LineBreakReplacement}bla{LineBreakReplacement}bla{LineBreakReplacement}bla");
    }
}
